﻿<cfsilent>
	<cfscript>
		
		event.setArg("pageTitle", "考场座次表");
		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		depId = sessionAdvice.getUserProp("teacherDepartment");
		termId = event.getArg("TermID", event.getArg("TID"));
		examType = event.getArg("ExamType");
	
		/* 任务列表 */
		sql = "SELECT 
					 b.task_exid, d.cr_id 
				FROM 
					 t_examtask b, t_clsroom_forexam a, t_course c, t_clsroom_timetable d 
				WHERE 
					 c.cid = b.cid 
					 AND 
					 d.crtime_id = a.crtime_Id 
					 AND 
					 b.task_exid = a.task_exid 
					 AND 
					 b.term_id = :termId 
					 AND 
					 b.exam_type = :examType 
					 AND 
					 b.task_prog = '3' 
					 and 
					 c.institute_id = :depID "; 
		
		queryObj = new query( datasource=application.dnsSlave );
		queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
		queryObj.addParam( name="examType", value=examType, cfsqltype="cf_sql_char" );
		queryObj.addParam( name="depID", value=depID, cfsqltype="cf_sql_varchar" );
		
		rs_room = queryObj.execute( sql=sql ).getResult();
	
		/* 默认显示行数及高度 */
		rowPerSlide = 8;
		rowPerPage = rowPerSlide * 7;
		
		/* Chrome Print Fix */
		if ( findNoCase( "Chrome", CGI.HTTP_USER_AGENT, 1) ) {
			rowPerSlide = 8;
			rowPerPage = rowPerSlide * 6;
		}
		
	</cfscript>
</cfsilent>

<cfif rs_room.recordCount>
<cfloop query="rs_room">
    <cfset sql = "SELECT 
                        t_examtask.task_exid, 
                        t_course.course_name,  
                        t_course.course_code, 
                        t_course.course_credit, 
                        t_institute.institute_name, 
                        t_term.academic_year, 
                        t_term.academic_term 	
                    FROM 
                        t_examtask 
                        INNER JOIN t_course ON t_course.cid = t_examtask.cid 
                        INNER JOIN t_institute ON t_institute.institute_id = t_course.institute_id 
                        INNER JOIN t_term ON t_term.term_id = t_examtask.term_id 
                    WHERE 
                        t_examtask.task_exid = :taskExid " />
                        
	<cfset queryObj = new query( datasource=application.dnsSlave ) />
	<cfset queryObj.addParam( name="taskExid", value=rs_room.task_exid, cfsqltype="cf_sql_char" ) />
	  
	<cfset rs_examTask = queryObj.execute( sql=sql ).getResult() />
    
    
   	<cfset sql = "SELECT classroom FROM t_classroom WHERE cr_id = :classroomId" />

	<cfset queryObj = new query( datasource=application.dnsSlave ) />
    <cfset queryObj.addParam( name="classroomId", value=rs_room.cr_id, cfsqltype="cf_sql_char" ) />
    
    <cfset rs_classRoom = queryObj.execute( sql=sql ).getResult() />
		
	<!---  /* 考场名单 */ --->
    <cfset sql = "SELECT 
					  t_student_exam.sitidx, 
					  t_student.stu_id, 
					  t_student.stu_name, 
					  t_student.stu_sex 
				  FROM 
					  t_student_exam 
					  INNER JOIN t_student ON t_student.stu_id = t_student_exam.stu_id 
				  WHERE 
					  t_student_exam.task_exid = :examId 
					  AND 
					  t_student_exam.cr_id = :clsroomId 
				  ORDER BY 
					  t_student_exam.sitidx " />
    
    <cfset queryObj = new query( datasource=application.dnsSlave ) />
    <cfset queryObj.addParam( name="examId", value=rs_room.task_exid, cfsqltype="cf_sql_char" ) />
    <cfset queryObj.addParam( name="clsroomId", value=rs_room.cr_id, cfsqltype="cf_sql_char" ) />
    
    <cfset rs_student = queryObj.execute( sql=sql ).getResult() />
 
	<cfset totlePageCount = 0 />
	<cfif rs_student.recordCount>
		
		<!--- /* 计算打印页数 */ --->
		<cfif rs_student.recordCount mod rowPerPage>
			<cfset totlePageCount = int(rs_student.recordCount/rowPerPage) + 1 />
			<cfelse>
			<cfset totlePageCount = int(rs_student.recordCount/rowPerPage) />
		</cfif>
		
		<cfset pageRowBegin = 1 />
		<cfset pageRowEnd = min(rowPerPage, rs_student.recordCount) />
		<cfset tagCode = "ZCB-" & rs_examTask.task_exid />
		
	</cfif>
	
	<!--- 考场间分页 --->
	<cfif rs_room["task_exid"][1] neq rs_room.task_exid>
		<div class="page_break"></div>
	</cfif>
	<cfloop from="1" to="#totlePageCount#" index="currentPage">
		<cfif currentPage GT 1>
			<div class="page_break"></div>
		</cfif>
		<div class="UIprintableTitle"><cfoutput>#rs_examTask.course_name#</cfoutput> <cfoutput>#rs_classRoom.classroom#</cfoutput> 考场座次表</div>
		<table width="98%" border="0" cellpadding="1" cellspacing="0">
			<tr>
				<td>课程号 <cfoutput>#rs_examTask.course_code#</cfoutput></td>
				<td>课程 <cfoutput>#rs_examTask.course_name#</cfoutput></td>
				<td>学分 <cfoutput>#numberFormat(rs_examTask.course_credit, "_.__")#</cfoutput></td>
				<td align="right">任课单位 <cfoutput>#rs_examTask.institute_name#</cfoutput></td>
			</tr>
			<tr>
				<td>学期 <cfoutput>#rs_examTask.academic_year#</cfoutput>-<cfoutput>#rs_examTask.academic_term#</cfoutput></td>
				<td>考场 <cfoutput>#rs_classRoom.classroom#</cfoutput></td>
				<td>考场人数 <cfoutput>#rs_student.recordCount#</cfoutput></td>
				<td align="right">第<cfoutput>#currentPage#</cfoutput>页 共<cfoutput>#totlePageCount#</cfoutput>页</td>
			</tr>
		</table>
		<div class="clear2px"></div>
		<table width="100%" cellpadding="0" cellspacing="0">
			<cfloop index="row" from="#pageRowBegin#" to="#pageRowEnd#">
				<cfif row mod rowPerSlide eq 1>
					<tr>
				</cfif>
				<td align="center" width="<cfoutput>#int(100/rowPerSlide)#</cfoutput>%"><div class="clear5px"></div>
					<div><img width="75" height="100" align="middle" src="<cfoutput>#getContextRoot()#</cfoutput>/acadmicManager/student/profile/<cfoutput>#rs_student["stu_id"][row]#</cfoutput>.jpg" /></div>
					<em><cfoutput>#rs_student["stu_id"][row]#</cfoutput><br/>
					<cfoutput>#rs_student["sitidx"][row]#</cfoutput> <cfoutput>#rs_student["stu_name"][row]#</cfoutput></em></td>
				
				<!--- 补空格 --->
				<cfif row eq pageRowEnd and row mod rowPerSlide gt 0>
					<cfloop from="1" to="#(rowPerSlide - (row mod rowPerSlide))#" index="space">
						<td width="<cfoutput>#int(100/rowPerSlide)#</cfoutput>%">&nbsp;<!-- <cfoutput>#space#</cfoutput> --></td>
					</cfloop>
				</cfif>
				<cfif row mod rowPerSlide eq 0>
					</tr>
				</cfif>
			</cfloop>
		</table>
		<div class="clear2px"></div>
		<table width="100%" cellpadding="0" cellspacing="0">
			<tr>
				<td width="150">打印时间 <cfoutput>#dateFormat(now(), "YYYY年MM月DD日")#</cfoutput></td>
				<td width="100">第 <cfoutput>#currentPage#</cfoutput> 页, 共 <cfoutput>#totlePageCount#</cfoutput> 页</td>
				<td align="right"><img src="<cfoutput>#getContextRoot()#</cfoutput>/barcode/Print/<cfoutput>#tagCode#</cfoutput>,<cfoutput>#currentPage#</cfoutput>.png" height="43"/></td>
			</tr>
		</table>
		<cfset pageRowBegin = pageRowBegin + rowPerPage />
		<cfset pageRowEnd = pageRowEnd + rowPerPage />
		<cfif pageRowEnd gt rs_student.recordCount>
			<cfset pageRowEnd = rs_student.recordCount />
		</cfif>
	</cfloop>
</cfloop>
</cfif>